<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="weixinicon/iconfont.css" />
		<link rel="stylesheet" href="css/header.css" />
		<script src="js/app.js"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init(

			);

			mui.plusReady(function() {
				plus.navigator.setStatusBarStyle("light");
				plus.navigator.setStatusBarBackground("#2f2f2f");
			});
		</script>
	</head>

	<body>

		<header class="mui-bar mui-bar-nav title">
			<h1 class="mui-title title-color" id="weixin_title"><b>易信</b></h1>
		</header>

		<nav class="mui-bar mui-bar-tab">
			<a class="mui-tab-item mui-active " tabindex="0">
				<span class="mui-icon iconfont icon-changjingguanli"></span>
				<span class="mui-tab-label">易信</span>
			</a>
			<a class="mui-tab-item" tabindex="1">
				<span class="mui-icon iconfont icon-quanxianshenpi"></span>
				<span class="mui-tab-label">通讯录</span>
			</a>
			<a class="mui-tab-item" tabindex="2">
				<span class="mui-icon iconfont icon-gongnengdingyi"></span>
				<span class="mui-tab-label">发现</span>
			</a>
			<a class="mui-tab-item" tabindex="3">
				<span class="mui-icon iconfont icon-zhanghaoquanxianguanli"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>
		<script type="text/javascript">
			var weixinArray = [{
					pageId: "weixin-chatlist.html",
					pageUrl: "weixin-chatlist.html"
				},
				{
					pageId: "weixin-contact.html",
					pageUrl: "weixin-contact.html"
				},
				{
					pageId: "weixin-discover.html",
					pageUrl: "weixin-discover.html"
				},
				{
					pageId: "weixin-me.html",
					pageUrl: "weixin-me.html"
				}
			];

			var weixinStyle = {
				top: "44px",
				bottom: "50px"
			};

			mui.plusReady(function() {

				// 扩展API加载完毕，现在可以正常调用扩展API
				// 添加监听从系统消息中心点击某条消息启动应用事件
				plus.push.addEventListener("click", function(msg) {
					// 分析msg.payload处理业务逻辑 
					var payload = JSON.parse(msg.payload);
					if(payload.type == app.CHATHINTS) {
						var friend = app.getFriendFromContactList(payload.friendId);
						var chatting = plus.webview.getWebviewById("chatting.html");
						mui.openWindow({
							url: "chatting.html",
							id: "chatting-" + payload.friendId,
							extras: {
								friendNickname: friend.friendAlias,
								friendImg: friend.friendImg,
								friendId: payload.friendId
							}

						});
					} else {
						mui.openWindow({
							url: "weixin-chatlist.html",
						});
					}
					plus.push.clear();
				}, false);

				//应用从推送服务器接收到推送消息事件
				/*plus.push.addEventListener("receive", function(msg) {
					// 分析msg.payload处理业务逻辑 
					alert("Recevied: " + msg.content);
				}, false);*/

				window.addEventListener("refresh", function() {
					var weixin_me = plus.webview.getWebviewById("weixin-me.html");
					var weixin_contact = plus.webview.getWebviewById("weixin-contact.html");
					var weixin_chatlist = plus.webview.getWebviewById("weixin-chatlist.html");
					mui.fire(weixin_chatlist, "refresh");
					mui.fire(weixin_me, "refresh");
					mui.fire(weixin_contact, "refresh");
				});

				//禁止返回到登陆页面

				mui.back = function() {
					return false;
				}

				//对网络连接进行事件监听
				netChageSwitch();

				//获取当前的webview对象
				var indexWebview = plus.webview.currentWebview();
				//向当前的主页webview追加子页的4张webview对象
				for(var i = 0; i < weixinArray.length; i++) {
					var weixinPage = plus.webview.create(weixinArray[i].pageUrl, weixinArray[i].pageId, weixinStyle);
					//隐藏webview窗口	
					weixinPage.hide();
					//追加每一个子页面到当前主页面
					indexWebview.append(weixinPage);
				}
				plus.webview.show(weixinArray[0].pageId);

				//批量绑定tap事件，展示不同的页面
				mui(".mui-bar-tab").on("tap", "a", function() {
					var tabindex = this.getAttribute("tabindex");

					//显示点击的tab选项所对应的页面
					plus.webview.show(weixinArray[tabindex].pageId, "fade-in", 200);

					//隐藏其他不需要的页面
					for(var i = 0; i < weixinArray.length; i++) {
						if(i != tabindex) {
							plus.webview.hide(weixinArray[i].pageId, "fade-out", 200);
						}
					}
				});
			});

			function netChageSwitch() {
				document.addEventListener("netchange", function() {
					var connectionStatus = plus.networkinfo.getCurrentType();
					if(connectionStatus != 0 && connectionStatus != 1) {
						var weixin_title = document.getElementById("weixin_title");
						weixin_title.innerHTML = "<b>易信</b>";
					} else {
						var weixin_title = document.getElementById("weixin_title");
						weixin_title.innerHTML = "<b>易信(未连接)</b>";
					}
				});
			}
		</script>
	</body>

</html>